﻿
@{
    Layout = null;
}

<div>
    <div class="input-group">
        <div class="col-3 pr-0" style="display: none">
            <label id="SelectWorkFlow-Lab-DomainName">@ViewData["DomainName"]</label>
            <label id="SelectWorkFlow-Lab-DomainId">@ViewData["DomainId"]</label>
            <label id="SelectWorkFlow-Lab-WorkFlowType">@ViewData["WorkFlowType"]</label>
            <label id="SelectWorkFlow-Lab-Parent-ModalID">@ViewData["ModalID"]</label>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">关联流程*</span>
        </div>
        <div class="col-9 pl-0 input-group">
            <select id="SelectWorkFlow-WorkFlow" class="form-control font-rfs border-radius-noleft" style="width:90%"></select>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">审批人*</span>
        </div>
        <div class="col-9 pl-0 input-group">
            <select id="SelectWorkFlow-User" class="form-control font-rfs border-radius-noleft" style="width:90%"></select>
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">发起说明</span>
        </div>
        <div class="col-9 pl-0">
            <input id="SelectWorkFlow-Description" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div>
    <br />
    <div class="text-right">
        <button id="SelectWorkFlow-confirm" class="btn btn-primary font-rfs">发起</button>
        <button id="SelectWorkFlow-cancel" type="button" class="btn btn-info font-rfs">取消</button>
    </div>
</div>

<script>

    $(document).ready(function() { 
        LoadWorkFlowByType('SelectWorkFlow-WorkFlow', $("#SelectWorkFlow-Lab-WorkFlowType").html());
        LoadUsers('SelectWorkFlow-User');
    });

    $("#SelectWorkFlow-confirm").click(function () {
        if ($("#SelectWorkFlow-WorkFlow").val().length == 0) {
            alert("必需选择要发起的流程！");
            $("#SelectWorkFlow-WorkFlow").addClass('error-style');
            return false;
        }
        if ($("#SelectWorkFlow-User").val().length == 0) {
            alert("必需选择一个审批人！");
            $("#SelectWorkFlow-User").addClass('error-style');
            return false;
        }

        $.post("/WorkFlow/Start", {
            WorkFlowId: $("#SelectWorkFlow-WorkFlow").find("option:selected").val(),
            DomainName: $("#SelectWorkFlow-Lab-DomainName").html(),
            DomainId: $("#SelectWorkFlow-Lab-DomainId").html(),
            ApprovedByID: $("#SelectWorkFlow-User").find("option:selected").val(),
            ApprovedByName: $("#SelectWorkFlow-User").find("option:selected").text(),
        }, function (data) {
            alert(data);
            $("#SelectWorkFlow-cancel").click();
        });

    });

    $("#SelectWorkFlow-cancel").click(function () {
        var modalID = $("#SelectWorkFlow-Lab-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });
    
</script>
